package com.cyn.service.impl;

import com.cyn.dao.SysUserMapper;
import com.cyn.entity.SysUser;
import com.cyn.service.SysUserService;
import com.cyn.service.TransactionalTestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    SysUserMapper sysUserMapper;

    @Autowired
    TransactionalTestService transactionalTestService;
    @Override
    public String test() {
        return "test";
    }

    @Override
    public SysUser get(Long id) {
        SysUser sysUser = sysUserMapper.get(id);
        return sysUser;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public SysUser insert(SysUser sysUser) {
        sysUserMapper.insert(sysUser);

        try {

            transactionalTestService.test();

        }catch (Exception e){
        }


        return sysUser;
    }

    @Transactional
    public SysUser insert2(SysUser sysUser) {
        sysUser.setLoginName("456");
        sysUserMapper.update(sysUser);

        return sysUser;
    }

    public static void main(String[] args) {
        System.out.println("YYYYMMDDHHMMSS".length());
    }
}
